//
//  DZListViewController.m
//  DaZhePrivateHomeCuisineClient
//
//  Created by zouzhisheng on 15-2-11.
//  Copyright (c) 2015年 zouzhisheng. All rights reserved.
//

#import "DZListViewController.h"
#import "DZRestautantModel.h"
#import "DZDinningRoomTableViewCell.h"
#import "DZDinningDetailViewController.h"
@interface DZListViewController ()

@end

@implementation DZListViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    if (_dataArray.count==0) {
        self.tempLabel.top=self.navView.bottom;
        self.tempLabel.height=SYSTEM_VERSION>=7.0?SCREEN_HEIGHT-self.navView.height:SCREEN_HEIGHT-self.navView.height-20;
    }else{
       [self.view addSubview:self.listView];
    }
    
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
-(UITableView *)listView
{
    if (!_listView) {
        _listView=[[UITableView alloc] initWithFrame:CGRectMake(0,self.navView.bottom,SCREEN_WIDTH,SYSTEM_VERSION>=7.0?SCREEN_HEIGHT-self.navView.height:SCREEN_HEIGHT-self.navView.height-20) style:UITableViewStylePlain];
        _listView.delegate=self;
        _listView.dataSource=self;
        _listView.backgroundColor=[UIColor clearColor];
        _listView.separatorStyle=UITableViewCellSeparatorStyleNone;
    }
    return _listView;
}
#pragma mark-UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _dataArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    id obj=_dataArray[indexPath.row];
    if ([obj isKindOfClass:[DZSubRestautantModel class]]) {
        static NSString *identifier = @"DZDinningRoomTableViewCell";
        DZDinningRoomTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
        if (!cell) {
            cell = [[[NSBundle mainBundle] loadNibNamed:@"DZDinningRoomTableViewCell"  owner:self options:nil] lastObject];
        }
        cell.selectionStyle=UITableViewCellSelectionStyleNone;
        [cell loadData:obj];
        return cell;
        
    }
    
    return nil;
}

#pragma mark-UITableViewDelegate
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    id obj=_dataArray[indexPath.row];
    if ([obj isKindOfClass:[DZSubRestautantModel class]]){
        return 90;
    }
    return 0;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    id obj=_dataArray[indexPath.row];
    if ([obj isKindOfClass:[DZSubRestautantModel class]]){
        DZSubRestautantModel *model=obj;
        DZDinningDetailViewController *dinningDetail=[[DZDinningDetailViewController alloc] init];
        dinningDetail.sid=model.sid;
        [self.navigationController pushViewController:dinningDetail animated:YES];
    }
    
}
-(void)tableView:(UITableView*)tableView  willDisplayCell:(UITableViewCell*)cell forRowAtIndexPath:(NSIndexPath*)indexPath
{
    [cell setBackgroundColor:[UIColor clearColor]];
}
-(void)backAction:(UIButton*)bt{
    [self.navigationController popViewControllerAnimated:YES];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
